<template>
  <div class="create-or-edit">
    <el-form>
      <el-form-item label="章节名称">
        <el-input v-model="chapter" disabled></el-input>
      </el-form-item>
      <el-form-item label="课时名称">
        <el-input v-model="section.theme"></el-input>
      </el-form-item>
      <el-form-item label="时长">
        <el-input v-model="section.duration">
          <template slot="append">分钟</template>
        </el-input>
      </el-form-item>
      <el-form-item label="是否开放试听" label-width="120px">
        <el-switch
          v-model="section.isFree"
          active-color="#13ce66"
          inactive-color="#ff4949"
        >
        </el-switch>
      </el-form-item>
      <el-form-item label="课时排序">
        <el-input v-model="section.orderNum" type="number" :min="0">
          <template slot="append">数字控制排序，数字越大越靠后</template>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="onCancel">取消</el-button>
        <el-button type="primary" @click="onSubmit">确认</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { saveOrUpdate } from "@/services/course-section";
export default {
  props: {
    chapter: {
      type: String,
    },
    section: {
      type: Object,
    },
  },
  methods: {
    onCancel() {
      // 设置取消状态，让父组件处理
      this.$emit("cancel");
    },
    async onSubmit() {
      const { data } = await saveOrUpdate(this.section);
      console.log(data);
      this.$emit("success");
      this.$message.success("添加成功");
    },
  },
};
</script>

<style lang="scss" scoped></style>
